package config;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by guo on 2017/9/17.
 */
public class FindPage {
    public int pageSize=3;
    public List<User> findPage(int page) throws SQLException {
        Connection connection=C3P0Untils.getConnettion();
        List<User> list=new ArrayList<>();
       String sql="select * from user order by id desc limit ?,?";
        PreparedStatement ps=connection.prepareStatement(sql);
        ps.setInt(1,(pageSize-1)*page);
        ps.setInt(2,pageSize);
        ResultSet set=ps.executeQuery();
        while(set.next())
        {
            User user=new User();
            user.setId(set.getInt(1));
            user.setUnname(set.getString(2));
            user.setPhone(set.getString(3));
            list.add(user);
        }
        return list;
    }
}
